from django.http import *
####################################################
#Examples:
#
#class newview(RESTview):
#    def do_get(self, request, *args, **kwargs):
#        do_something()
#    def do_post(self,request):
#        do_another_thing()
####################################################

class RESTview(object):
    def __new__(cls, request, *args, **kwargs):
        instance = super(RESTview, cls).__new__(cls)
        try:
            if request.method == 'GET':
                res = instance.do_get(request, *args, **kwargs)
            elif request.method == 'POST':
                res = instance.do_post(request, *args, **kwargs)
            elif request.method == 'PUT':
                res = instance.do_put(request, *args, **kwargs)
            elif request.method == 'DELETE':
                res = instance.do_delete(request, *args, **kwargs)
            else:
                #@todo: raise mcifun.Http405
                raise Http404
            return res
        except AttributeError:
            #@todo: raise mcifun.Http405
            raise Http404